home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: [Help] I can't find my error.
- Date: 25 Feb 1996 19:29:49 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4gqutt$i1f@umbc9.umbc.edu>
- References: <4ggvgr$1b2@aurora.engr.LaTech.edu>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- |> Could anyone please tell me why the following program won't work?
- |>
- |> *********************************************************
- |> /* This program will ask your name and age; and then
- |> will print your name and age for next year back */
- |>
- |> #include <stdio.h>
- |>
- |> main()
- |> {
- |> char name;
- |> int age, next_age;
- |>
- |> printf("%s\n","Please enter your name and age: ");
- |> scanf("%s%d\n", &name, &age);
-
- Why do you use %s when you clearly have 'name' declared as a single
- char. So either use %c in which case we'll assume you know a lot of people
- with 1 letter names /* OR */ make your declaration an array of acceptable
- length to how long you expect the average name to be. Using 'char name[80]'
- should be more than enough.
-
- |> next_age= age + 1;
- |> printf("Hi, %s ,next year, you will be %d\n", name, next_age);
-
- Might want to add a 'return (0);' here.
- |> }
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-